

import datetime

import requests

from common.setting import ensure_path_sep
from utils.mysqlUtils.db_pool import Database
import os
import threading
import time
from common.setting import ensure_path_sep
from utils.logging_tool.log_control import LogHandler
from utils.mysqlUtils.db_pool import Database

current_path = os.path.abspath(__file__)
current_dir = os.path.dirname(current_path)
path_list = current_path.split("\\")
dis_path = "\\".join(path_list[-2:-1])


def remove_file(info_path):
    if os.path.exists(info_path):
        os.remove(info_path)
    else:
        print(f"{info_path} 不存在")


info_path = ensure_path_sep(f"\\logs\\info-{dis_path}{time.time()}")
error_path = ensure_path_sep(f"\\logs\\\error-{dis_path}{time.time()}.log")
warning_path = ensure_path_sep(f"\\logs\\warning-{dis_path}{time.time()}.log")
remove_file(info_path)
remove_file(error_path)
remove_file(warning_path)
INFO = LogHandler(info_path, level='info')
ERROR = LogHandler(error_path, level='error')
WARNING = LogHandler(warning_path, level='warning')


class SkuFilter:


    def test001(self):
        db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "test_jdw_database")
        sql = """
        SELECT sku FROM `test_zhcxkj_center_strategy`.`t_shopee_product_rules_sku` WHERE `product_rules_template_id` = 14
        """
        """
        得到各个平台销量
        """
        res = db.fetch_all_tuple(sql, ())
        for sku in res:
            url = """http://apiep.zhcxkj.com/ProductEdit/GetProductEditInfo"""

            param = {
                    "input":{
                    "CustomerID":1,
                    "SKU":[sku[0]],
                    "EditStatus":1
                    }
                    }

            hearders = {
                "Content-Type": "application/json",
                "Authorization": "Basic aXJvYm90Ym94OmkxcjVvOEJvdGJveA==",
            }

            res = requests.post(url=url, headers=hearders, json=param)
            if res:
                data_List = res.json().get('data')[0].get('ProductDetail')
                for i in data_List:
                    languageType  = i['languageType']
                    if languageType == "EN":
                        productDesc = i['productDesc']
                        if not productDesc.find("Features"):
                            print(sku)
                    else:
                        continue




if __name__ == '__main__':
    SkuFilter().test001()
